<!doctype html>
<html>

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
        <title>APICloud APP</title>
        <link rel="stylesheet" type="text/css" href="../css/api.css" />
        <style>
            header {
                background: #FCFCFC;
                height: 50px;
                border-bottom: 1px solid #DDDFE3;
            }
            
            .back {
                position: absolute;
                left: 0px;
                bottom: 0px;
                width: 50px;
                height: 50px;
                background: url(../image/header/back.png) center center no-repeat;
                background-size: 15px auto;
            }
            
            .menu {
                position: absolute;
                left: 90px;
                right: 90px;
                bottom: 10px;
                background-color: #fcfcfc;
                height: 30px;
                line-height: 30px;
                border-radius: 4px;
                color: #fff;
                text-align: center;
                border: 1px solid #f63;
            }
            
            .menu .menu-item {
                position: relative;
                float: left;
                width: 50%;
                height: 30px;
                display: inline-block;
                color: #FF6633;
            }
            
            .menu .menu-item.active {
                background-color: #FF6633;
                color: #fff;
            }
            
            .menu .menu-item:first-child {
                border-radius: 4px 0 0 4px;
            }
            
            .menu .menu-item:last-child {
                border-radius: 0px 4px 4px 0px;
            }
        </style>
    </head>

    <body>
        <header id="header">
            <div class="back event-back"></div>
            <div class="menu">
                <div class="menu-item" tapmode="active" onclick="fnChange(0);">商户</div>
                <div class="menu-item" tapmode="active" onclick="fnChange(1)">团购</div>
            </div>
        </header>
    </body>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/common.js"></script>
    <script type="text/javascript">
        apiready = function() {
            fnReady();
            fnInit();
            fnChangeStyle(api.pageParam.type);

            fnInitShoplist();
        };

        var menus;

        function fnInit() {
            menus = $api.domAll(header, '.menu-item');
            fnChangeStyle(api.pageParam.type);
        };

        function fnChangeStyle(index) {
            for (var i = 0; i < menus.length; i++) {
                if (i == index) {
                    $api.addCls(menus[i], 'active');
                } else {
                    $api.removeCls(menus[i], 'active');
                }
            }
        };

        var frameNames = ['shoplist_frame', 'groupbuylist_frame'];

        function fnInitShoplist() {
            var frames = [];
            for (var i = 0; i < frameNames.length; i++) {
                frames.push({
                    name: frameNames[i],
                    url: './shoplist_frame.html',
                    bounces: false,
                    vScrollBarEnabled: false,
                    hScrollBarEnabled: false,
                    bgColor: '#f0f0f0',
                    pageParam: {
                        type: i,
                        shopType: api.pageParam.shopType
                    }
                });
            }

            api.openFrameGroup({
                name: 'shoplist_group',
                scrollEnabled: true,
                rect: {
                    x: 0,
                    y: headerHeight,
                    w: 'auto',
                    h: 'auto'
                },
                index: api.pageParam.type,
                frames: frames
            }, function(ret, err) {
                fnChangeStyle(ret.index);
            });
        };

        function fnChange(index) {
            fnChangeStyle(index);

            api.setFrameGroupIndex({
                name: 'shoplist_group',
                index: index,
                scroll: true
            });
        };
    </script>

</html>
